﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace RAMED.Controls
{
    public partial class Toast : Control
    {



        public Toast()
        {
             SetStyle(ControlStyles.AllPaintingInWmPaint,true);
             SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
             SetStyle(ControlStyles.UserPaint, true);
             SetStyle(ControlStyles.SupportsTransparentBackColor, true);

        }

        private bool istransparent = false;

        public bool Istransparent
        {
            get { return istransparent; }
            set 
            { 
                istransparent = value;
                if (value == true)
                {
                    this.BackColor = Color.Transparent;
                }

                Invalidate();
            }
        }




        protected override void OnPaintBackground(PaintEventArgs e)
        {
            base.OnPaintBackground(e);
              if (Istransparent) 
              {
                 if  (Parent != null) 
                {
                    int myIndex   = Parent.Controls.GetChildIndex(this);
                    for(  int i = Parent.Controls.Count - 1 ; i <  myIndex + 1 ; i--)
    
                    {  
                        Control  ctrl = Parent.Controls[i];
                        if (ctrl.Bounds.IntersectsWith(Bounds)) 
                        {
                            if (ctrl.Visible) 
                            {
                                Bitmap bmp   = new Bitmap(ctrl.Width, ctrl.Height);
                                ctrl.DrawToBitmap(bmp, ctrl.ClientRectangle);
                                e.Graphics.TranslateTransform(ctrl.Left - Left, ctrl.Top - Top);
                                e.Graphics.DrawImage(bmp, Point.Empty);
                                e.Graphics.TranslateTransform(Left - ctrl.Left, Top - ctrl.Top);
                                bmp.Dispose();
                            }
                        }
                    }
                }

              }




        }

    }
}
